Trò chơi đua xe động vật trong UNITY Engine
114.848 lượt xem;
- BackShopButtonListener.cs
- ShopScreen /
- AnimalRacing /
- Scripts /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4 public class BackShopButtonListener : InputAdapter {
5
6 public GameObject shopLayer;
7 public GameObject pickSkillLayer;
8
9 //BackButton
10 public override void OnTouchDown()
11 {
12 if (InputController.Name != InputNames.SHOP) return;
13 base.OnTouchDown();
14 gameObject.transform.localScale = new Vector3(0.9f, 0.9f, 1);
15 SoundManager.playButtonSound();
16 }
17 public override void OnCheckUp()
18 {
19 if (InputController.Name != InputNames.SHOP) return;
20 base.OnCheckUp();
21 gameObject.transform.localScale = new Vector3(1, 1, 1);
22 }
23 public override void OnTouchUp()
24 {
25 if (InputController.Name != InputNames.SHOP) return;
26 base.OnTouchUp();
27 backPressed();
28 }
29
30 public void Update()
31 {
32 if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Backspace))
33 {
34 if(InputController.Name != InputNames.DIALOG)
35 backPressed();
36 }
37 }
38
39 private void backPressed()
40 {
41 if (shopLayer.transform.localPosition.x == 0)
42 {
43 if (shopLayer.GetComponent<Actor>() != null)
44 Destroy(shopLayer.GetComponent<Actor>());
45 shopLayer.AddComponent<Actor>().addAction(new ActionSequence(
46 new ActionScaleTo(0, 0, 0.5f, Interpolation.swingIn),
47 new ActionRunnable(new Runnable(delegate()
48 {
49 Application.LoadLevel("LevelScreen");
50 }))
51 ));
52 }
53 else if (shopLayer.transform.localPosition.x == -8)
54 {
55 shopLayer.SetActive(true);
56 if (shopLayer.GetComponent<Actor>() != null)
57 Destroy(shopLayer.GetComponent<Actor>());
58 shopLayer.AddComponent<Actor>().addAction(new ActionMoveTo(0, 0, 0.3f));
59
60 if (pickSkillLayer.GetComponent<Actor>() != null)
61 Destroy(pickSkillLayer.GetComponent<Actor>());
62 pickSkillLayer.AddComponent<Actor>().addAction(new ActionSequence(
63 new ActionMoveTo(8, 0, 0.3f), new ActionRunnable(delegate() { pickSkillLayer.SetActive(false); })));
64 }
65 }
66 }
2 using System.Collections;
3
4 public class BackShopButtonListener : InputAdapter {
5
6 public GameObject shopLayer;
7 public GameObject pickSkillLayer;
8
9 //BackButton
10 public override void OnTouchDown()
11 {
12 if (InputController.Name != InputNames.SHOP) return;
13 base.OnTouchDown();
14 gameObject.transform.localScale = new Vector3(0.9f, 0.9f, 1);
15 SoundManager.playButtonSound();
16 }
17 public override void OnCheckUp()
18 {
19 if (InputController.Name != InputNames.SHOP) return;
20 base.OnCheckUp();
21 gameObject.transform.localScale = new Vector3(1, 1, 1);
22 }
23 public override void OnTouchUp()
24 {
25 if (InputController.Name != InputNames.SHOP) return;
26 base.OnTouchUp();
27 backPressed();
28 }
29
30 public void Update()
31 {
32 if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Backspace))
33 {
34 if(InputController.Name != InputNames.DIALOG)
35 backPressed();
36 }
37 }
38
39 private void backPressed()
40 {
41 if (shopLayer.transform.localPosition.x == 0)
42 {
43 if (shopLayer.GetComponent<Actor>() != null)
44 Destroy(shopLayer.GetComponent<Actor>());
45 shopLayer.AddComponent<Actor>().addAction(new ActionSequence(
46 new ActionScaleTo(0, 0, 0.5f, Interpolation.swingIn),
47 new ActionRunnable(new Runnable(delegate()
48 {
49 Application.LoadLevel("LevelScreen");
50 }))
51 ));
52 }
53 else if (shopLayer.transform.localPosition.x == -8)
54 {
55 shopLayer.SetActive(true);
56 if (shopLayer.GetComponent<Actor>() != null)
57 Destroy(shopLayer.GetComponent<Actor>());
58 shopLayer.AddComponent<Actor>().addAction(new ActionMoveTo(0, 0, 0.3f));
59
60 if (pickSkillLayer.GetComponent<Actor>() != null)
61 Destroy(pickSkillLayer.GetComponent<Actor>());
62 pickSkillLayer.AddComponent<Actor>().addAction(new ActionSequence(
63 new ActionMoveTo(8, 0, 0.3f), new ActionRunnable(delegate() { pickSkillLayer.SetActive(false); })));
64 }
65 }
66 }
BackButton